package com.sky.mapper;


import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {


    /**
     * 根据条件动态查询购物车数据。
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> selectCartByshopping(ShoppingCart shoppingCart);

    /**
     * 插入购物车的数据
     * @param shoppingCart shoppingCart
     */
    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) values " +
            "(#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime});")
    void insertShoppingIntoCart(ShoppingCart shoppingCart);

    /**
     * 修改购物车中商品数量
     * @param
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateShoppingNumberById(ShoppingCart shoppingCart);

    @Delete("delete from shopping_cart where user_id = #{currentId}")
    void deleteAllShoppings(Long currentId);


    @Delete("delete from shopping_cart where  id = #{id}")
    void deleteShoppingById(Long id);

    /**
     * 批量插入购物车数据
     *
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
